nition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode ret(0,head),*p=&ret,*q;
        while(p->next){
            if(p->next->next && p->next->val == p->next->next->val)
            {
                q = p->next->next;
                while(q && q->val == p->next->val) q=q->next;
                p->next = q;
            }
            else
            {
                p = p->next;
            }
        }
        return ret.next;
    }
};

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode ret(0,head),*p=&ret,*q;
        while(p->next){
            if(p->next->next && p->next->val == p->next->next->val)
            {
                q = p->next->next;
                while(q && q->val == p->next->val) q=q->next;
                p->next = q;
            }
            else
            {
                p = p->next;
            }
        }
        return ret.next;
    }
};

class Solution {
public:
    int GetNext(int n)
    {
        int ret = 0;
        while(n)
        {
            ret += (n%10)*(n%10);
            n/=10;
        }
        return ret;
    }
    bool isHappy(int n) {
        int p=n;
        int q=n;
        do{
            p = GetNext(p);
            q = GetNext(GetNext(q));
        }while(p!=q && q!=1);
        return q==1;
    }
};

class Solution {
public:
    int GetNext(int n)
    {
        int ret = 0;
        while(n)
        {
            ret += (n%10)*(n%10);
            n/=10;
        }
        return ret;
    }
    bool isHappy(int n) {
        int p=n;
        int q=n;
        do{
            p = GetNext(p);
            q = GetNext(GetNext(q));
        }while(p!=q && q!=1);
        return q==1;
    }
};

class Solution {
public:
    int GetNext(int n)
    {
        int ret = 0;
        while(n)
        {
            ret += (n%10)*(n%10);
            n/=10;
        }
        return ret;
    }
    bool isHappy(int n) {
        int p=n;
        int q=n;
        do{
            p = GetNext(p);
            q = GetNext(GetNext(q));
        }while(p!=q && q!=1);
        return q==1;
    }
};

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* _reverseN(ListNode* head,int n)
    {
        if(n==1) return head;
        ListNode* tail = head->next,*p = _reverseN(head->next,n-1);
        head->next = tail->next;
        tail->next = head;
        return p;
    }
    ListNode* reverseN(ListNode* head,int n)
    {
        ListNode* p=head;
        int cnt =n;
        while(--n && p)p=p->next;
        if(p==nullptr) return head;
        return _reverseN(head,cnt);
    }
    ListNode* reverseKGroup(ListNode* head, int k) {
        ListNode ret(0,head),*p = &ret,*q=p->next;
        //==q说明没有翻转
        while((p->next = reverseN(q,k))!=q)
        {
            p=q;
            q=p->next;
        }
        return ret.next;
    }
};

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* _reverseN(ListNode* head,int n)
    {
        if(n==1) return head;
        ListNode* tail = head->next,*p = _reverseN(head->next,n-1);
        head->next = tail->next;
        tail->next = head;
        return p;
    }
    ListNode* reverseN(ListNode* head,int n)
    {
        ListNode* p=head;
        int cnt =n;
        while(--n && p)p=p->next;
        if(p==nullptr) return head;
        return _reverseN(head,cnt);
    }
    ListNode* reverseKGroup(ListNode* head, int k) {
        ListNode ret(0,head),*p = &ret,*q=p->next;
        //==q说明没有翻转
        while((p->next = reverseN(q,k))!=q)
        {
            p=q;
            q=p->next;
        }
        return ret.next;
    }
};

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* _reverseN(ListNode* head,int n)
    {
        if(n==1) return head;
        ListNode* tail = head->next,*p = _reverseN(head->next,n-1);
        head->next = tail->next;
        tail->next = head;
        return p;
    }
    ListNode* reverseN(ListNode* head,int n)
    {
        ListNode* p=head;
        int cnt =n;
        while(--n && p)p=p->next;
        if(p==nullptr) return head;
        return _reverseN(head,cnt);
    }
    ListNode* reverseKGroup(ListNode* head, int k) {
        ListNode ret(0,head),*p = &ret,*q=p->next;
        //==q说明没有翻转
        while((p->next = reverseN(q,k))!=q)
        {
            p=q;
            q=p->next;
        }
        return ret.next;
    }
};

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* _reverseN(ListNode* head,int n)
    {
        if(n==1) return head;
        ListNode* tail = head->next,*p = _reverseN(head->next,n-1);
        head->next = tail->next;
        tail->next = head;
        return p;
    }
    ListNode* reverseN(ListNode* head,int n)
    {
        ListNode* p=head;
        int cnt =n;
        while(--n && p)p=p->next;
        if(p==nullptr) return head;
        return _reverseN(head,cnt);
    }
    ListNode* reverseKGroup(ListNode* head, int k) {
        ListNode ret(0,head),*p = &ret,*q=p->next;
        //==q说明没有翻转
        while((p->next = reverseN(q,k))!=q)
        {
            p=q;
            q=p->next;
        }
        return ret.next;
    }
};

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* _reverseN(ListNode* head,int n)
    {
        if(n==1) return head;
        ListNode* tail = head->next,*p = _reverseN(head->next,n-1);
        head->next = tail->next;
        tail->next = head;
        return p;
    }
    ListNode* reverseN(ListNode* head,int n)
    {
        ListNode* p=head;
        int cnt =n;
        while(--n && p)p=p->next;
        if(p==nullptr) return head;
        return _reverseN(head,cnt);
    }
    ListNode* reverseKGroup(ListNode* head, int k) {
        ListNode ret(0,head),*p = &ret,*q=p->next;
        //==q说明没有翻转
        while((p->next = reverseN(q,k))!=q)
        {
            p=q;
            q=p->next;
        }
        return ret.next;
    }
};
